from django.http.response import HttpResponse
import sys


def bad_request(request, exception):
    print(request.META['REMOTE_ADDR'], exception.args[0]['path'], 'bad_request')
    sys.stdout.flush()
    return HttpResponse('<h2>url错误</h2>')


def page_not_found(request, exception):
    print(request.META['REMOTE_ADDR'], exception.args[0]['path'], 'page_not_found')
    sys.stdout.flush()
    return HttpResponse('<h2>找不到页面</h2>')


def server_error(request):
    print(request.META['REMOTE_ADDR'], request.META['PATH_INFO'], 'server_error')
    print(request.body)
    sys.stdout.flush()
    return HttpResponse('<h2>服务器错误</h2>')
